<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
        .time-item {
            width: 450px;
            height: 45px;
            margin: 0 auto;
        }

        .time-item strong {
            background: orange;
            color: #fff;
            line-height: 49px;
            font-size: 36px;
            font-family: Arial;
            padding: 0 10px;
            margin-right: 10px;
            border-radius: 5px;
            box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.2);
        }

        .time-item>span {
            float: left;
            line-height: 49px;
            color: orange;
            font-size: 32px;
            margin: 0 10px;
            font-family: Arial, Helvetica, sans-serif;
        }

        .title {
            width: 260px;
            height: 50px;
            margin: 200px auto 50px auto;
        }
    </style>

</head>

<body>
    <h1 class="title">距离七夕，还有</h1>

    <div class="time-item">
        <span><span id="day">00</span>天</span>
        <strong><span id="hour">00</span>时</strong>
        <strong><span id="minute">00</span>分</strong>
        <strong><span id="second">00</span>秒</strong>
    </div>
    <script>
        function duRan() {
            // 创建时间对象 
            var target = new Date('2023-08-22 00:00:00');
            var current = new Date();


            target_time = target.getTime();
            current_time = current.getTime();


            var res = parseInt((target_time - current_time) / 1000)

            console.log(res);
            // 1天 = 24 * 3600 
            // 1小时 = 3600
            // 1分钟 = 60 
            // ...
            var days = parseInt(res / (24 * 3600));
            var hours = parseInt(res % (24 * 3600) / 3600);
            var minutes = parseInt(res % 3600 / 60);
            var seconds = res % 60;



            // 找到存放元素的标签  

            // 天
            document.getElementById('day').innerHTML = days
            // 小时
            document.getElementById('hour').innerHTML = hours
            // 分钟
            document.getElementById('minute').innerHTML = minutes
            // 秒
            document.getElementById('second').innerHTML = seconds

        }


    //  setInterval(duRan,1000)
     setInterval("duRan()",1000)

    </script>
</body>

</html>